package com.wisedu.w5autocode.wizards;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import com.wisedu.w5autocode.MyPropertyModel;

public class ClassJoinTreeProvider implements IStructuredContentProvider, ITreeContentProvider {

	@Override
	public void dispose() {

	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

	}

	@Override
	public Object[] getChildren(Object parentElement) {
		MyPropertyModel mpm = (MyPropertyModel) parentElement;
		return mpm.getChildrenProperties().toArray();
	}

	@Override
	public Object getParent(Object element) {
		return null;
	}

	@Override
	public boolean hasChildren(Object element) {
		MyPropertyModel mpm = (MyPropertyModel) element;
		return CollectionUtils.isNotEmpty(mpm.getChildrenProperties());
	}

	@Override
	public Object[] getElements(Object inputElement) {
		if (inputElement instanceof List) {
			List input = (List) inputElement;
			return input.toArray();
		}
		return new Object[0];
	}

}
